<template>
  <a-card :bordered="false" >
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" v-if="!detailShow">
      <a-form layout="inline" @keyup.enter.native="searchQuery" :labelCol="{ style: 'width: 100px' }">
        <a-row :gutter="24">
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="地铁路线">
              <a-input :value="lineName" disabled=""></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :md="5" :sm="24" >
            <a-form-item label="站台名称">
                <a-input v-model="queryParam.platformName" placeholder="请输入站台名称"></a-input>
            </a-form-item>
          </a-col>  -->
          <a-col :md="5" :sm="24">
            <a-form-item label="站台类别">
                <a-select
                v-model="queryParam.deviceCategory"
                placeholder="请选择站台类别"
                :getPopupContainer="
                  (triggerNode) => {
                    return triggerNode.parentNode;
                  }
                "
              >
                <a-select-option
                  v-for="item in equipmentCategory"
                  :value="item.value"
                  :key="item.value"
                  >{{ item.name }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>                       


          <a-col :md="5" :sm="24" >
            <a-form-item label="设备位置">
                <a-select
                v-model="queryParam.deviceLocation"
                placeholder="请选择设备位置" >
                <a-select-option value="SYS">站台</a-select-option>
                <a-select-option value="UP">上行</a-select-option>
                <a-select-option value="DOWN">下行</a-select-option>
              </a-select>
            </a-form-item>
          </a-col> 
          <a-col :md="5" :sm="24">
            <a-form-item label="设备类型">
                <a-select
                v-model="queryParam.deviceTypeId"
                placeholder="请选择设备类型"
                :getPopupContainer="
                  (triggerNode) => {
                    return triggerNode.parentNode;
                  }
                "
              >
                <a-select-option
                  v-for="item in equipmentType"
                  :value="item.id"
                  :key="item.id"
                  >{{ item.typeName }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>  
          <a-col :md="5" :sm="24">
            <a-form-item label="设备名称" >
              <J-input placeholder="请输入设备名称" v-model="queryParam.deviceName"></J-input>
            </a-form-item>
          </a-col>                
         <a-col :md="4" :sm="24" >
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>  

         
        </a-row>
        <a-row :gutter="24">

          <a-col :md="5" :sm="24">
            <a-form-item label="设备编码">
              <J-input placeholder="请输入设备编码" v-model="queryParam.deviceCode"></J-input>
            </a-form-item>
          </a-col>
        </a-row>        
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="!detailShow">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('设备管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div v-if="!detailShow">
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <!-- <a @click="handleDetail(record)">详情</a> -->
          <a :disabled="record.deviceCode=='SYS'" @click="getDetail(record)">详情</a>

          <!-- <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>

      </a-table>
    </div>

    <gd-device-modal ref="modalForm" @ok="modalFormOk"></gd-device-modal>
    <!-- <div @click="detailHide" style="text-align: right;" v-if="detailShow"><a-icon type="close-circle" :style="{ fontSize: '20px', color: '#ccc' }"/></div> -->
    <!-- <equipment-detail v-if="detailShow" :equipData="equipDetail" @showList="detailShow=false"></equipment-detail> -->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GdDeviceModal from './modules/GdDeviceModal'
  import EquipmentDetail from './EquipmentDetail.vue'
  import { postAction,getAction } from '@/api/manage'

  export default {
    name: 'GdDeviceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      GdDeviceModal,
      EquipmentDetail
    },
    data () {
      return {
        description: '设备管理管理页面',
        lineName:sessionStorage.getItem('lineName'),
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          // {
          //   title:'设备ID',
          //   align:"center",
          //   dataIndex: 'id'
          // },
          {
            title:'站台名称',
            align:"center",
            dataIndex: 'platformName'
          },
          {
            title:'站台类别',
            align:"center",
            dataIndex: 'deviceCategory'
          },
          {
            title:'设备位置',
            align:"center",
            dataIndex: 'deviceLocation'
          },
          {
            title:'设备类型',
            align:"center",
            dataIndex: 'typeName'
          },          
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'deviceName'
          },
          {
            title:'设备编码',
            align:"center",
            dataIndex: 'deviceCode'
          },

          // {
          //   title:'设备健康类型id',
          //   align:"center",
          //   dataIndex: 'deviceHealthyTypeId_dictText'
          // },
          // {
          //   title:'运行时长',
          //   align:"center",
          //   dataIndex: 'runningTime'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/basic/gdDevice/list",
          delete: "/basic/gdDevice/delete",
          deleteBatch: "/basic/gdDevice/deleteBatch",
          exportXlsUrl: "/basic/gdDevice/exportXls",
          importExcelUrl: "basic/gdDevice/importExcel",
          
        },
        queryParam:{parentId:0},
        dictOptions:{},
        superFieldList:[],
        advanced: false,
        detailShow:false,
        //设备详情
        equipDetail:{}
      }
    },
    created() {
    this.getEquipmentType()
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      getDetail(record){
        console.log('record=>>',record)
        // this.equipDetail =record;
        // this.detailShow = true
        // 1111111111
        this.$router.push({path:'equipmentList/detail',query:{'type':record.alias,'id':record.id}})

      },
      detailHide(){
        this.detailShow = false
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .j-table-force-nowrap >>> .ant-empty-normal {
      margin: 200px 0 !important;
    }
</style>